﻿using System;
using FlyWebFrame.Model;
using System.IO;
using Fly.Data;

namespace FlyWebFrame.Action.admin
{
    public class addschedule : baseaction
    {
        public int edit_id;
        public string err;

        public int courseId;
        public string cost;
        public string certs;
        public string language;
        public string lecturer;
        public string location;
        public int dayStart;
        public int monthStart;
        public int dayEnd;
        public int monthEnd;
        public int timeHrs;

        public dynamic courselist;

        public override void Treat()
        {
            contentleft = "/html/admin/editschedule.htm";
            page_title = "LEAD Consulting - Thêm lịch khai giảng";
            admin_script = "$('#ad_schedule').addClass('active');";

            Courses course = new Courses();
            courselist = course.Get().Data;

            Schedule s = new Schedule();

            if (Form["submit"] == "true")
            {
                err = "";
                courseId = Int32.Parse(Form["course"]);
                cost = Form["cost"];
                certs = Form["certs"];
                language = Form["language"];
                lecturer = Form["lecturer"];
                location = Form["location"];
                dayStart = Int32.Parse(Form["dayStart"]);
                monthStart = Int32.Parse(Form["monthStart"]);
                dayEnd = Int32.Parse(Form["dayEnd"]);
                monthEnd = Int32.Parse(Form["monthEnd"]);
                timeHrs = Int32.Parse(Form["timeHrs"]);

                if (err != "")
                {
                    admin_script += "$('#err-newsedit').removeClass('hidden');$('#err-newsedit').html('" + err + "');";
                }
                else
                {
                    s.courseId = courseId;
                    s.cost = cost;
                    s.certs = certs;
                    s.language = language;
                    s.lecturer = lecturer;
                    s.location = location;
                    s.dayStart = dayStart;
                    s.monthStart = monthStart;
                    s.dayEnd = dayEnd;
                    s.monthEnd = monthEnd;
                    s.timeHrs = timeHrs;

                    if (s.Add())
                    {
                        Redirect("/admin/schedules");
                        admin_script += "$('#msg-newsedit').removeClass('hidden');";
                    }
                    else
                    {
                        admin_script += "$('#err-newsedit').removeClass('hidden');$('#err-newsedit').html('dữ liệu bạn nhập không hợp lệ');";
                    }
                }
            }
            else
            {
                err = "Not submitted";
            }

        }
        
    }
}